package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/11.
 */
@HttpInlet(Conn.ACTIVITY_ORDER_LIST)
public class AppointmentListGet extends BaseAsyGet<AppointmentListGet.OrderListEntity> {

    public String user_id;
    public int page;

    public AppointmentListGet(AsyCallBack<OrderListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected OrderListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONObject mainObject = object.optJSONObject("data");

            OrderListEntity orderListEntity = new OrderListEntity();

            orderListEntity.current_page = mainObject.optInt("current_page");
            orderListEntity.total = mainObject.optInt("total");
            orderListEntity.per_page = mainObject.optInt("per_page");

            JSONArray array = mainObject.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                OrderEntity orderEntity = new OrderEntity();

                orderEntity.id = entityObject.optString("id");
                orderEntity.p_id = entityObject.optString("p_id");
                orderEntity.title = entityObject.optString("title");
                orderEntity.datetimes = entityObject.optString("datetimes");
                orderEntity.time_tip = entityObject.optString("time_tip");
                orderEntity.starttime = entityObject.optString("starttime");
                orderEntity.endtime = entityObject.optString("endtime");
                orderEntity.name = entityObject.optString("name");
                orderEntity.mobile = entityObject.optString("mobile");
                orderEntity.ischild = entityObject.optString("ischild");
                orderEntity.payway = entityObject.optString("payway");
                orderEntity.checkinfo = entityObject.optString("checkinfo");
                orderEntity.evaluate_status = entityObject.optString("evaluate_status");

                orderListEntity.orderEntityList.add(orderEntity);

            }

            return orderListEntity;

        }

        return null;
    }

    public static class OrderListEntity {

        public int total, per_page, current_page;

        public List<OrderEntity> orderEntityList = new ArrayList<>();
    }

    public static class OrderEntity {

//        {
//            "id": 1, //id
//                "title": "测试4", //活动名称
//                "datetimes": "2017-01-10",//预约时间
//                "time_tip": "上午",//预定场次
//                "starttime": "10:00",//开始时间
//                "endtime": "11:30", //结束时间
//                "name": "阿坤", //姓名
//                "mobile": "15846520240",//手机号
//                "ischild": 1, //带儿童 1是 0否
//                "payway": "微信支付"//支付状态
//            "checkinfo": 2   // 2 待出票 3 已出票 4 已评价
//            "evaluate_status": 2, //评价状态 1是 2否
//        }

        public String id, p_id, title, datetimes, time_tip, starttime, endtime, name, mobile, ischild, payway, checkinfo, evaluate_status;

    }
}
